package com.ruoyi.web.controller.danger;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.entity.TVisitor;
import com.ruoyi.system.service.TVisitorService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * (访客)表控制层
 * @since 2023-04-21 15:35:17
 */
@RestController
@RequestMapping("tVisitor")
public class TVisitorController  extends BaseController {

    @Resource
    private TVisitorService tVisitorService;

    /**
     * 分页查询
     * @return 查询结果
     */
    @GetMapping("/list")
    public TableDataInfo queryByPage(TVisitor tVisitor) {
        startPage();
        List<TVisitor> tVisitors = this.tVisitorService.queryByPage(tVisitor);
        return getDataTable(tVisitors);
    }


    /**
     * 通过主键查询单条数据
     * @return 单条数据
     */
    @GetMapping("{visitorPhone}")
    public AjaxResult queryById(@PathVariable("visitorPhone") String visitorPhone) {
        return AjaxResult.success(this.tVisitorService.queryById(visitorPhone));
    }

    /**
     * 新增数据
     * @param tVisitor 实体
     * @return 新增结果
     */
    @PostMapping("/create")
    public AjaxResult add(TVisitor tVisitor) {
        return AjaxResult.success(this.tVisitorService.insert(tVisitor));
    }

    /**
     * 编辑数据
     * @param tVisitor 实体
     * @return 编辑结果
     */
    @PostMapping("/update")
    public AjaxResult edit(TVisitor tVisitor) {
        return AjaxResult.success(this.tVisitorService.update(tVisitor));
    }

    /**
     * 删除数据
     * @param id 主键
     * @return 删除是否成功
     */
    @GetMapping("/delete")
    public AjaxResult deleteById(String visitorPhone) {
        return AjaxResult.success(this.tVisitorService.deleteById(visitorPhone));
    }

}

